﻿using System;
using System.Windows.Forms;

namespace Learn_eventSubscribe01
{
    class Program
    {
        static void Main(string[] args)
        {
            // 事件的来源和事件的响应者是两个对象
            Form form = new Form();
            Controller controller = new Controller(form);

            form.ShowDialog();
        }
    }

    class Controller
    {
        private Form form;

        // 按ctor快速实现构造函数
        public Controller(Form form)
        {
            if(form != null)
            {
                this.form = form;
                this.form.Click += this.Form_Click;
            }
        }

        private void Form_Click(object sender, EventArgs e)
        {
            this.form.Text = DateTime.Now.ToString();
        }
    }
}
